package com.party.core.service.gatherInfo.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.gatherInfo.GatherInfoItineraryReadDao;
import com.party.core.dao.write.gatherInfo.GatherInfoItineraryWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.gatherInfo.GatherInfoItinerary;
import com.party.core.service.gatherInfo.IGatherInfoItineraryService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Author: Administrator.
 * @Description: 行程信息
 * @Date:Created in 2017/10/10 0010 下午 16:52.
 */
@Service
public class GatherInfoItineraryService implements IGatherInfoItineraryService {
    @Autowired
    private GatherInfoItineraryWriteDao gatherInfoItineraryWriteDao;

    @Autowired
    private GatherInfoItineraryReadDao gatherInfoItineraryReadDao;

    @Override
    public String insert(GatherInfoItinerary t) {
        BaseModel.preInsert(t);
        boolean result = gatherInfoItineraryWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(GatherInfoItinerary t) {
        t.setUpdateDate(new Date());
        return gatherInfoItineraryWriteDao.update(t);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return gatherInfoItineraryWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return gatherInfoItineraryWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return gatherInfoItineraryWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return gatherInfoItineraryWriteDao.batchDelete(ids);
    }

    @Override
    public GatherInfoItinerary get(String id) {
        return gatherInfoItineraryReadDao.get(id);
    }

    @Override
    public List<GatherInfoItinerary> listPage(GatherInfoItinerary t, Page page) {
        return gatherInfoItineraryReadDao.listPage(t, page);
    }

    @Override
    public List<GatherInfoItinerary> list(GatherInfoItinerary t) {
        return gatherInfoItineraryReadDao.listPage(t, null);
    }

    @Override
    public List<GatherInfoItinerary> batchList(Set<String> ids, GatherInfoItinerary t, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return gatherInfoItineraryReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public void deleteByInfoMemberId(String infoMemberId) {
        gatherInfoItineraryWriteDao.deleteByInfoMemberId(infoMemberId);
    }
}
